package com.ymatou.userservice.testcase;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.userservice.parameter.SinaWeiBoUserRequestDtoBean;
import com.ymatou.userservice.service.SinaWeiBoUserRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.business.service.AuthCallService;
import com.ymttest.business.service.UserCallService;
import com.ymttest.database.model.YmtUsers;
import com.ymttest.database.mongo.UserTokenWapper;
import com.ymttest.database.sqlwapper.LoginHistoryWapper;
import com.ymttest.database.sqlwapper.YmtUsersWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.constant.AppTypeChannel;
import com.ymttest.utils.constant.ECode;
import com.ymttest.utils.constant.ThirdPartyType;

import oracle.jdbc.util.Login;
/**
*微博用户注册接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SinaWeiBoUserRequestDto{
	private static SinaWeiBoUserRequestDtoBean regBean;
	private static SinaWeiBoUserRequestDtoCall regCall;
	private static UserTokenWapper userTokenWapper;
	private static YmtUsersWapper userWapper;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("微博用户注册 ");
	}

	@Before
	public void caseUp() throws Exception {
		regBean = new SinaWeiBoUserRequestDtoBean();
		regCall = new SinaWeiBoUserRequestDtoCall();
		userTokenWapper = new UserTokenWapper();
		userWapper = new YmtUsersWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(regCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_001() {
		Logger.start(true,"微博账号第一次授权,创建用户成功");
		try {
			String weiboUserId = "aliReg_"+TestDataManager.getRandomNum(10);
			Logger.comment("微博账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微博账号");
			String phone = TestDataManager.getPhoneNum();
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(phone);
			regBean.setRegSource(1);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("和数据库进行数据校验");
			Thread.sleep(1000);
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_SinaWeibo", "sWeiboUserId", weiboUserId);
			int userId = (Integer)user.get("YmatouUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			Thread.sleep(1000);
			Map m=new HashMap<>();
			m.put("Uid", userId);
			Map history=new LoginHistoryWapper().selectUserRegHistoryByUid(m).get(0);
			Logger.debug(history);
			Logger.verifyEquals(regBean.getDeviceId(), history.get("DeviceId"), "验证凭据DeviceId");
			Logger.verifyEquals(regBean.getSName().toLowerCase(), history.get("LoginId").toString(), "验证凭据LoginId");
			Logger.verifyEquals(regBean.getMobile(), history.get("Mobile"), "验证凭据Mobile");
			Logger.verifyEquals(regBean.getClientIp(), history.get("ClientIp"), "验证凭据ClientIp");
			Logger.verifyEquals("Weibo", history.get("ChannelSource"), "验证凭据ChannelSource");
			//1 App
			Logger.verifyEquals("App", history.get("RegSource"), "验证凭据RegSource");
			Logger.verifyEquals(regBean.getEquimentid(), history.get("Equimentid"), "验证凭据Equimentid");
			YmtUsers user1 = new YmtUsersWapper().getYmtUsers(userId);
			//验证cellphone
			Logger.verifyEquals(phone, user1.getScellphone(), "验证cellphone");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_002() {
		Logger.start(true,"用户已存在（非第一次授权），则用户直接登录成功");
		try {
			Map thirdParty = userWapper.selectOneThirdPartyBindPhone("YmatouUserId", "sWeiboUserId", "Ymt_User_At_SinaWeibo");
			String weiboUserId = thirdParty.get("sWeiboUserId").toString();
			String sAccountName = thirdParty.get("sAccountName").toString();
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_NO);
			regBean.setSWeiboUserId(thirdParty.get("sWeiboUserId").toString());
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setRegSource(1);
			regBean.setTokenSource("app");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(sAccountName);
			regCall.setData(regBean);
			regCall.callService();			
			Logger.verifyEquals("登录成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			Logger.verifyIsNull( regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_SinaWeibo", "sWeiboUserId", weiboUserId);
			int userId = (Integer)user.get("YmatouUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.comment("对比数据库信息");
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_003() {
		Logger.start(false,"手机号已绑定过其他微博账号，继续用该手机号绑定微博账号，失败");
		try {
			String phone = TestDataManager.getPhoneNum();
			String oldWeiboUserId = "weibo_"+TestDataManager.getRandomNum(10);
			UserCallService.regByWeibo(oldWeiboUserId, phone, true, "注册成功");
			
			String weiboUserId = "weibonew_"+TestDataManager.getRandomNum(10);
			Logger.comment("微博账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_YES);
			
			Logger.comment("验证手机号绑定过微博账号");
			UserCallService.checkMobileIsBindThirdParty(phone, weiboUserId, ThirdPartyType.WEIBO, ECode.USER_YES);
			
			Logger.comment("继续使用该手机号，注册微博账号");
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setRegSource(1);
			regBean.setMobile(phone);
			regCall.setData(regBean);
			regCall.callService();
			
			Logger.verifyEquals("false", regCall.getString("Success"), "验证操作是否成功");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证Code");
			Logger.verifyEquals("该手机号码已经绑定过微博了，换一个试试吧~", regCall.getString("LastErrorMessage"), "验证Msg信息");
			Logger.verifyEquals("AlreadyUnionMatouUser", regCall.getResult().get("VerifyCode"), "验证verifyCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_004() {
		Logger.start(true,"手机号已经注册过码头账号，选择继续绑定");
		try {
			Logger.comment("手机注册洋码头账号");
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.registerUser(null, phone,null);
			
			Logger.comment("检查手机绑定了码头账号");
			UserCallService.checkMobileIsBindYmtUser(phone, ECode.USER_YES);
			
			String weiboUserId = "ali_"+TestDataManager.getRandomNum(10);
			Logger.comment("验证手机号是否绑定过微博账号");
			UserCallService.checkMobileIsBindThirdParty(phone, weiboUserId, ThirdPartyType.WEIBO, ECode.USER_NO);
			
			Logger.comment("继续使用该手机号，注册微博账号");
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(phone);
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setRegSource(1);
			regBean.setMobile(phone);
			regCall.setData(regBean);
			regCall.callService();

			Logger.verifyEquals("登录成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("检查该用户绑定了微博账号");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboUserId, true);
			UserCallService.checkThirdPartyBindYmt((Integer)user.get("userId"), thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_005() {
		Logger.start(false,"不输入手机创建用户失败");
		try {
			regBean.setSWeiboUserId("BindWeibotest_"+TestDataManager.getRandomNum(10));
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setRegSource(1);
			regCall.setData(regBean);
			regCall.callService();
			
			Logger.verifyEquals("为了您的账户安全，请绑定你的手机号码", regCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("NeedBindMobile", regCall.getResult().get("VerifyCode"), "验证凭证");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_006() {
		Logger.start(true,"输入已关联过的用户(sWeiBoUserId已存在) ，则用户直接登录成功");
		try {
			Map thirdParty = userWapper.selectOneThirdPartyBindPhone("YmatouUserId", "sWeiboUserId", "Ymt_User_At_SinaWeibo");
			UserCallService.checkThirdPartyNeedBindMobile(thirdParty.get("sWeiboUserId").toString(), ThirdPartyType.WEIBO, ECode.USER_NO);
			regBean.setSWeiboUserId(thirdParty.get("sWeiboUserId").toString());
			regBean.setSName("atuoTest");
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setRegSource(1);
			regCall.setData(regBean);
			regCall.callService();		
			
			Logger.verifyEquals("登录成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			Logger.verifyIsNull(regCall.getResult().get("Remark"), "验证remark信息");
			
			Thread.sleep(1000);
			Map userToken = userTokenWapper.getUserTokenByUid(((Double)regCall.getResult().get("UserId")).intValue());
			//TOKEN 新旧？待确认
//			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals(true,AuthCallService.signAuth(regCall.getResult().get("Token").toString()).get("success"),"验证token可用");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_007() {
		Logger.start(false,"不输入微博用户Id，用户创建失败");
		try {
			regBean.setSName("atuoTest");
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setRegSource(1);
			regCall.setData(regBean);
			regCall.callService();		
			
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("新浪微博Id不能为空", regCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals(-1d, regCall.getResult().get("UserId"), "验证用户ID");
			Logger.verifyIsNull(regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("SinaWeiBoIdIsEmpty", regCall.getResult().get("VerifyCode"), "验证凭据");
			Logger.verifyIsNull(regCall.getResult().get("Remark"), "验证remark信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_008() {
		Logger.start(true,"用户绑定了A微博账号->解绑A微博账号->绑定B微博账号(手机号与A相同)->绑定成功");
		try {
			String phone = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微博账号");
			String weiboIdA = "unbindweibo_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeibo(weiboIdA, phone, true, "登录成功");
			
			Logger.comment("绑定B微博账号(手机号与A相同)");
			String weiboIdB = "unbindweibo_"+TestDataManager.getRandomNum(10); 
			UserCallService.regByWeibo(weiboIdB, phone, false, "该手机号码已经绑定过微博了，换一个试试吧~");
			
			int userId = ((Double)user.get("userId")).intValue();
			Logger.comment("解绑A微博账号");
			Map result = UserCallService.unbindThirdParty(userId, weiboIdA, ThirdPartyType.WEIBO);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			
			Logger.comment("再次绑定B微博账号(手机号与A相同)");
			UserCallService.regByWeibo(weiboIdB, phone, true, "登录成功");
			
			Logger.comment("验证用户的绑定情况");
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboIdA, false);
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboIdB, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_009() {
		Logger.start(true,"用户绑定了A微博账号->解绑A微博账号->绑定B微博账号(微博号与A相同，手机号与A不同，手机未绑定过码头账号)->绑定成功");
		try {
			String phone = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微博账号");
			String weiboA = "unbindali_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeibo(weiboA, phone, true, "登录成功");
			int userId = ((Double)user.get("userId")).intValue();
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑A微博账号");
			Map result = UserCallService.unbindThirdParty(userId, weiboA, ThirdPartyType.WEIBO);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("绑定B微博账号(微信号与A相同，手机号与A不同)");
			String phoneB = TestDataManager.getPhoneNum();
			UserCallService.checkThirdPartyNeedBindMobile(weiboA, ThirdPartyType.WEIBO, ECode.USER_YES);
			UserCallService.checkMobileIsBindThirdParty(phoneB, weiboA, ThirdPartyType.WEIBO, ECode.USER_NO);
			Map bindUser = UserCallService.regByWeibo(weiboA, phoneB, true, "注册成功");
			int newUserId = ((Double)bindUser.get("userId")).intValue();
			Logger.verifyNotEquals(userId, newUserId, "验证创建了一个新用户");
			
			Logger.comment("验证新用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, true);
			UserCallService.checkThirdPartyBindYmt(newUserId, thirdParty);
			
			Logger.comment("验证老用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_010() {
		Logger.start(true,"用户绑定了A微博账号->解绑A微博账号->绑定A微博账号->绑定成功");
		try {
			String phone = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微博账号");
			String weiboA = "unbindali_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeibo(weiboA, phone, true, "登录成功");
			int userId = ((Double)user.get("userId")).intValue();
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑A微博账号");
			Map result = UserCallService.unbindThirdParty(userId, weiboA, ThirdPartyType.WEIBO);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("绑定A微博账号");
			UserCallService.checkThirdPartyNeedBindMobile(weiboA, ThirdPartyType.WEIBO, ECode.USER_YES);
			UserCallService.checkMobileIsBindThirdParty(phone, weiboA, ThirdPartyType.WEIBO, ECode.USER_NO);
			Map bindUser = UserCallService.regByWeibo(weiboA, phone, true, "登录成功");
			int newUserId = ((Double)bindUser.get("userId")).intValue();
			Logger.verifyEquals(userId, newUserId, "验证绑定前后是同一个用户");
			
			Logger.comment("验证用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, true);
			UserCallService.checkThirdPartyBindYmt(newUserId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_011() {
		Logger.start(true,"用户绑定了A微博账号->解绑A微博账号->绑定B微博账号(微博号与A相同，手机号与A不同，已绑定过码头账号)->绑定成功");
		try {
			String phone = TestDataManager.getPhoneNum();
			Logger.comment("注册码头账号");
			UserCallService.registerUser(null, phone,null);
			
			Logger.comment("绑定了A微博账号");
			String weiboA = "unbindali_"+TestDataManager.getRandomNum(10);
			Map user = UserCallService.regByWeibo(weiboA, phone, true, "登录成功");
			int userId = ((Double)user.get("userId")).intValue();
			List<Map> thirdParty = new ArrayList<Map>();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, true);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("解绑A微博账号");
			Map result = UserCallService.unbindThirdParty(userId, weiboA, ThirdPartyType.WEIBO);
			Logger.verifyEquals(200d, result.get("ResponseCode"), "验证Code");
			Logger.verifyEquals(true, result.get("Success"), "验证是否成功");
			Logger.verifyEquals("ok", result.get("Result"), "验证Msg信息");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
			
			Logger.comment("绑定B微博账号(微信号与A相同，手机号与A不同，已绑定过码头账号)");
			String phoneB = TestDataManager.getPhoneNum();
			Map userB = UserCallService.registerUser(null, phoneB,null);
			UserCallService.checkThirdPartyNeedBindMobile(weiboA, ThirdPartyType.WEIBO, ECode.USER_YES);
			UserCallService.checkMobileIsBindThirdParty(phoneB, weiboA, ThirdPartyType.WEIBO, ECode.USER_NO);
			UserCallService.checkMobileIsBindYmtUser(phoneB, "yes");
			Map bindUser = UserCallService.regByWeibo(weiboA, phoneB, true, "登录成功");
			int newUserId = ((Double)bindUser.get("userId")).intValue();
			Logger.verifyEquals((Integer)userB.get("userId"), newUserId, "验证绑定到了新用户B");
			
			Logger.comment("验证新用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, true);
			UserCallService.checkThirdPartyBindYmt(newUserId, thirdParty);
			
			Logger.comment("验证老用户的绑定情况");
			thirdParty.clear();
			UserCallService.addThirdPartyAccount(thirdParty, ThirdPartyType.WEIBO, weiboA, false);
			UserCallService.checkThirdPartyBindYmt(userId, thirdParty);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_012() {
		Logger.start(false,"第三方用户已存在（非第一次授权）,绑定不同的手机号，则返回当前账号已绑定");
		try {
			Map thirdParty = userWapper.selectOneThirdPartyBindPhone("YmatouUserId", "sWeiboUserId", "Ymt_User_At_SinaWeibo");
			String weiboUserId = thirdParty.get("sWeiboUserId").toString();
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_NO);
			
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setRegSource(1);
			regBean.setMobile(TestDataManager.getPhoneNum());
			regCall.setData(regBean);
			regCall.callService();			
			Logger.verifyEquals("当前账号已绑定", regCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("AlreadyUnionMatouUser", regCall.getResult().get("VerifyCode"), "验证凭据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_013() {
		Logger.start(false,"手机号已经注册过码头账号，第三方账号也绑定过码头账号，绑定失败");
		try {
			Logger.comment("手机注册洋码头账号");
			String phone = TestDataManager.getPhoneNum();
			Map user = UserCallService.registerUser(null, phone,null);
			
			Logger.comment("检查手机绑定了码头账号");
			UserCallService.checkMobileIsBindYmtUser(phone, ECode.USER_YES);
			
			Logger.comment("微博账号也绑定过其他码头账号");
			String weiboUserId = "ali_"+TestDataManager.getRandomNum(10);
			UserCallService.regByWeibo(weiboUserId, TestDataManager.getPhoneNum(), true, "注册成功");
			
			Logger.comment("继续使用该手机号，注册微博账号");
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(phone);
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setRegSource(1);
			regBean.setMobile(phone);
			regCall.setData(regBean);
			regCall.callService();

			Logger.verifyEquals("当前账号已绑定", regCall.getString("LastErrorMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			Logger.verifyEquals("AlreadyUnionMatouUser", regCall.getResult().get("VerifyCode"), "验证凭据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_014() {
		Logger.start(true,"微博账号第一次授权,用户名超过20位,创建用户成功");
		try {
			String weiboUserId = "aliReg_"+TestDataManager.getRandomNum(20);
			Logger.comment("微博账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微博账号");
			String phone = TestDataManager.getPhoneNum();
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(20));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(phone);
			regBean.setRegSource(1);
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("和数据库进行数据校验");
			Thread.sleep(1000);
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_SinaWeibo", "sWeiboUserId", weiboUserId);
			int userId = (Integer)user.get("YmatouUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_015() {
		Logger.start(false,"微博账号第一次授权,用户名超过100位,创建用户失败");
		try {
			String weiboUserId = "aliReg_"+TestDataManager.getRandomNum(100);
			Logger.comment("微博账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微博账号");
			String phone = TestDataManager.getPhoneNum();
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(100));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(phone);
			regBean.setRegSource(1);
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("400", regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			String VerifyCode=regCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("LoginNameLengthError", VerifyCode, "验证返回的LoginNameLengthError信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_016() {
		Logger.start(true,"传入TokenSource为sellerapp用户注册成功JIRACONN-2123");
		try {
			String weiboUserId = "aliReg_"+TestDataManager.getRandomNum(10);
			Logger.comment("微博账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微博账号");
			String phone = TestDataManager.getPhoneNum();
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(phone);
			regBean.setRegSource(1);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regBean.setTokenSource("sellerapp");
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("和数据库进行数据校验");
			Thread.sleep(1000);
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_SinaWeibo", "sWeiboUserId", weiboUserId);
			int userId = (Integer)user.get("YmatouUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			Thread.sleep(1000);
			Map m=new HashMap<>();
			m.put("Uid", userId);
			Map history=new LoginHistoryWapper().selectUserRegHistoryByUid(m).get(0);
			Logger.debug(history);
			Logger.verifyEquals(regBean.getDeviceId(), history.get("DeviceId"), "验证凭据DeviceId");
			Logger.verifyEquals(regBean.getSName().toLowerCase(), history.get("LoginId").toString(), "验证凭据LoginId");
			Logger.verifyEquals(regBean.getMobile(), history.get("Mobile"), "验证凭据Mobile");
			Logger.verifyEquals(regBean.getClientIp(), history.get("ClientIp"), "验证凭据ClientIp");
			Logger.verifyEquals("Weibo", history.get("ChannelSource"), "验证凭据ChannelSource");
			//1 App
			Logger.verifyEquals("App", history.get("RegSource"), "验证凭据RegSource");
			Logger.verifyEquals(regBean.getEquimentid(), history.get("Equimentid"), "验证凭据Equimentid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_017() {
		Logger.start(true,"传入TokenSource为app用户注册成功JIRACONN-2123");
		try {
			String weiboUserId = "aliReg_"+TestDataManager.getRandomNum(10);
			Logger.comment("微博账号第一次授权，检查需要绑定手机号");
			UserCallService.checkThirdPartyNeedBindMobile(weiboUserId, ThirdPartyType.WEIBO, ECode.USER_YES);
			
			Logger.comment("绑定手机号，注册微博账号");
			String phone = TestDataManager.getPhoneNum();
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("weiboTest_"+TestDataManager.getRandomNum(10));
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(phone);
			regBean.setRegSource(1);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regBean.setTokenSource("app");
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals("注册成功", regCall.getString("SuccessMessage"), "验证返回的Message信息");
			Logger.verifyEquals(ECode.SUCCESS, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("true", regCall.getString("Success"), "验证是否成功");
			
			Logger.comment("和数据库进行数据校验");
			Thread.sleep(1000);
			Map user = userWapper.getThirdPartyByThirdPartyId("Ymt_User_At_SinaWeibo", "sWeiboUserId", weiboUserId);
			int userId = (Integer)user.get("YmatouUserId");
			Map userToken = userTokenWapper.getUserTokenByUid(userId);
			Logger.verifyEquals(userToken.get("uId"), ((Double)regCall.getResult().get("UserId")).intValue(), "验证用户ID");
			Logger.verifyEquals(userToken.get("sId"), regCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals("new", regCall.getResult().get("Remark"), "验证Remark信息");
			Logger.verifyEquals("Success", regCall.getResult().get("VerifyCode"), "验证凭据");
			Thread.sleep(1000);
			Map m=new HashMap<>();
			m.put("Uid", userId);
			Map history=new LoginHistoryWapper().selectUserRegHistoryByUid(m).get(0);
			Logger.debug(history);
			Logger.verifyEquals(regBean.getDeviceId(), history.get("DeviceId"), "验证凭据DeviceId");
			Logger.verifyEquals(regBean.getSName().toLowerCase(), history.get("LoginId").toString(), "验证凭据LoginId");
			Logger.verifyEquals(regBean.getMobile(), history.get("Mobile"), "验证凭据Mobile");
			Logger.verifyEquals(regBean.getClientIp(), history.get("ClientIp"), "验证凭据ClientIp");
			Logger.verifyEquals("Weibo", history.get("ChannelSource"), "验证凭据ChannelSource");
			//1 App
			Logger.verifyEquals("App", history.get("RegSource"), "验证凭据RegSource");
			Logger.verifyEquals(regBean.getEquimentid(), history.get("Equimentid"), "验证凭据Equimentid");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SinaWeiBoUserRequestDto_018() {
		Logger.start(false,"特殊字符用户名失败JIRACONN-2522");
		try {
			String weiboUserId = "weiboReg_"+TestDataManager.getRandomNum(10);
			
			Logger.comment("绑定手机号，注册微博账号");
			String phone = TestDataManager.getPhoneNum();
			regBean.setSWeiboUserId(weiboUserId);
			regBean.setSName("~!@#$%^&*");
			regBean.setSMail(TestDataManager.getEmail());
			regBean.setSMobile(TestDataManager.getPhoneNum());
			regBean.setClientIp("120.1.1.1");
			regBean.setDAddTime(YMTDateUtil.getBeforeOrNextDay(-1));
			regBean.setTerminalSource("ios");
			regBean.setAppTypeChanndel(AppTypeChannel.NEW_CHANNEL);
			regBean.setMobile(phone);
			regBean.setRegSource(1);
			regBean.setDeviceId(TestDataManager.getRandomUUID().toString());
			regBean.setEquimentid(TestDataManager.getRandomUUID().toString());
			regCall.setData(regBean);
			regCall.callService();
			Logger.verifyEquals(ECode.ERROR400, regCall.getString("ResponseCode"), "验证code");
			Logger.verifyEquals("false", regCall.getString("Success"), "验证是否成功");
			String VerifyCode=regCall.getJsonObject().get("Result").getAsJsonObject().get("VerifyCode").getAsString();
			Logger.verifyEquals("LoginNameContextError", VerifyCode, "验证返回的LoginNameContextError信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}